<?php
namespace app\index\controller;
use think\Exception;

class Tongji extends Base
{
    public function __construct()
    {
        parent::__construct();
    }

    // 员工业绩统计
    public function manageCount()
    {
    	$post = input();//starttime endtime
        $where = [];
        if (isset($post['starttime']) && isset($post['endtime'])) {
            if (!empty($post['starttime']) && !empty($post['endtime'])) {
                $where['date'] = array(array('egt',strtotime($post['starttime'])),array('elt',strtotime($post['endtime'])));
            }else{
                apiReturn(201,'请选择时间');
            }
        }else{
            apiReturn(201,'请选择时间');
        }
        $where['order_status'] = ['neq',11];
        if ($this->is_xiaoshou == 1) {
            $where['manage_id'] = $this->getManageList();
        }
        $list = db('crm_order')->where($where)->field('manage_id,manage_name,zu_id,zu_name,sum(total) as total_sum,sum(ding_price) as ding_price_sum,sum(daishou_price) as daishou_price_sum')->group('manage_id')->order('zu_id ASC')->select();
        apiReturn(200,'获取成功',$list);
    }

    // 分组业绩统计
    public function fenzuCount()
    {
    	$post = input();//starttime endtime
        $where = [];
        if (isset($post['starttime']) && isset($post['endtime'])) {
            if (!empty($post['starttime']) && !empty($post['endtime'])) {
                $where['date'] = array(array('egt',strtotime($post['starttime'])),array('elt',strtotime($post['endtime'])));
            }else{
                apiReturn(201,'请选择时间');
            }
        }else{
            apiReturn(201,'请选择时间');
        }
        $where['order_status'] = ['neq',11];
        if ($this->is_xiaoshou == 1) {
            $where['manage_id'] = $this->getManageList();
        }
        $list = db('crm_order')->where($where)->field('zu_id,zu_name,sum(total) as total_sum,sum(ding_price) as ding_price_sum,sum(daishou_price) as daishou_price_sum')->group('zu_id')->order('zu_id ASC')->select();
        apiReturn(200,'获取成功',$list);
    }

}
